<link rel="stylesheet" type="text/css" href="css/datepicker_vista.css" /> 
<link rel="stylesheet" type="text/css" href="css/upload_attach.css" /> 

<script type="text/javascript" src="jscript/Fx.ProgressBar.js"></script>
<script type="text/javascript" src="jscript/Swiff.Uploader.js"></script>
<script type="text/javascript" src="jscript/FancyUpload3.Attach.js"></script>

<script type="text/javascript" src="jscript/datepicker.js"></script> 
<script type="text/javascript" src="jscript/upload_attach.js"></script> 
<script type="text/javascript">
	/* pelaku */
	function karyawanPelaku_search(){	//dipake
		FBModal_show2(APP.action, 'post', "proc=karyawanPelaku-search-modal", true, true);
	}
	
	function karyawanPelaku_search_list(form){	//dipake
		form.set('send', {
			url: APP.action,
			method: 'post',
			onSuccess: function(response) {$('karyawanPelaku-search-table').set('html', response);}
		}).send();
	}
	
	function karyawanPelaku_search_pick(karyID, karyNama){	//dipake
		$('pelaku_karyawan_nik').value=karyID;
		$('pelaku_karyawan_nama').value=karyNama;
	}
	
	/* pelapor */
	function karyawanPelapor_search(){
		FBModal_show2(APP.action, 'post', "proc=karyawanPelapor-search-modal", true, true);
	}
	
	function karyawanPelapor_search_list(form){
		form.set('send', {
			url: APP.action,
			method: 'post',
			onSuccess: function(response) {$('karyawanPelapor-search-table').set('html', response);}
		}).send();
	}
	
	function karyawanPelapor_search_pick(karyID, karyNama){
		$('pelapor_karyawan_nik').value=karyID;
		$('pelapor_karyawan_nama').value=karyNama;
	}
	
	/* pelapor */
	function pelapor_search(){
		FBModal_show2(APP.action, 'post', "proc=pelapor-search-modal", true, true);
	}
	
	function pelapor_search_list(form){
		form.set('send', {
			url: APP.action,
			method: 'post',
			onSuccess: function(response) {$('pelapor-search-table').set('html', response);}
		}).send();
	}
	
	function pelapor_search_pick(data){
		var type = data.nik? 1 : 2;
		$$('input[name:lapor_id]').each(function(item){
			if (item.value == type) item.checked=true; 
		});
		
		if (type==1){
			$$('.inp-karyawan').setStyle('display', 'table-row'); 
			$$('.inp-nonKaryawan').setStyle('display', 'none');
			$('lapor_id').value = data.laporId;
			$('pelapor_karyawan_nik').value=data.nik;
			$('pelapor_karyawan_nama').value=data.nama;
		}
		else if (type==2){
			$$('.inp-karyawan').setStyle('display', 'none'); 
			$$('.inp-nonKaryawan').setStyle('display', 'table-row');	
			$('lapor_id').value = data.laporId;
			$('pelapor_nonkaryawan_nama').value=data.nama;
			alamat_load(data.laporId)	//load alamat
			tlp_load(data.laporId);		//load tlp
		}
	}
	
	function pelapor_search_reset(){
		$('lapor_id').value= $('pelapor_karyawan_nik').value= $('pelapor_karyawan_nama').value=
		$('lapor_id').value= $('pelapor_nonkaryawan_nama').value='';
		alamat_load('')		//load alamat
		tlp_load('');		//load tlp
	}
	
	/* add tlp */
	function tlp_add(el){
		//show the loading indicator
		FBModal_show2(
			APP.action, 
			'post', 
			"proc=tlp-modal&title=Add Telepon",
			true, true);
	}
	
	var TLP_TABLE_ID = 0;
	function tlp_save(form){
		FBModal_hide();
		//request the data
		var id = ++TLP_TABLE_ID;
		tlp = form.tlp.value;
		if (tlp=='' || !tlp) return;
		new Request({
			url: 'proc/admin/perbuatan.php',
			method: 'post',
			onSuccess: function (res){
				$('tlp-table').innerHTML += res;
			}
		}).send("proc=tlp-list&tlp="+ tlp + "&id=tlp-table"+ id);
	}
	
	function tlp_delete(el, tlp){ 
		if ($defined(tlp)){
			doRequest(APP.action, 'post', 'proc=tlp-delete&tlp='+tlp, null);
		}
		$(el).nix(); 
	}

	function tlp_load(lapor_id){
		doRequest(APP.action, 'post', 'proc=tlp-load&lapor_id='+lapor_id, null,
			function(res){ 
				$('tlp-table').set('html',res);
			});
	}

	/*add alamat*/
	function alamat_add(){
		//show the loading indicator
		FBModal_show2(
			APP.action, 
			'post', 
			"proc=alamat-modal",
			true, true);
	}
	
	/*save alamat*/
	var ALAMAT_TABLE_ID = 0;
	function alamat_save(form){
		var id = ++ALAMAT_TABLE_ID;
		if (form.alamat.value=='' && form.kodePos.value=='' && form.kodeArea=='' && fm.kota.value=='' && fm.propinsi.value=='') 
			return;
		
		new Request({
			url: APP.action,
			method: 'post',
			onSuccess: function (res){
				FBModal_hide();
				$('alamat-table').innerHTML += res;
			}	
		}).send("proc=alamat-list&" +
				"id=alamat-table"+ id +"&" +
				"alamat="+ form.alamat.value +"&" +
				"kodePos="+ form.kodePos.value +"&" +
				"kodeArea="+ form.kodeArea.value +"&" +
				"kota="+ form.kota.value +"&" +
				"propinsi="+ form.propinsi.value);
		FBModal_loading("Save", "Please wait...", true, false);
	}
	
	/*delete alamat*/
	function alamat_delete(el){
		$(el).nix();
	}
	
	function alamat_load(lapor_id){
		doRequest(APP.action, 'post', 'proc=alamat-load&lapor_id='+lapor_id, null,
			function(res){ 
				$('alamat-table').set('html',res);
			});
	}
	
	function doAdd_bidangCombo(jenis, target){
		doRequest(APP.action, 'post', 'proc=combo-bidang&achiev_jenis='+jenis, null,
			function(res){ 
				target.set('html',res); 
				doAdd_tingkatCombo(jenis, target.value, $('detachiev_tingkat'));
			});
	}
	
	function doAdd_tingkatCombo(jenis, bidang, target){
		doRequest(APP.action, 'post', 'proc=combo-tingkat&achiev_bidang='+bidang+'&achiev_jenis='+jenis, null,
			function(res){ 
				target.set('html',res); 
				doAdd_kategoriCombo(jenis, bidang, target.value, $('detachiev_id')); 
			});
	}
	
	function doAdd_kategoriCombo(jenis, bidang, tingkat, target){
		doRequest(APP.action, 'post', 'proc=combo-kategori&achiev_bidang='+bidang+'&achiev_jenis='+jenis+'&detachiev_tingkat='+tingkat, null,
			function(res){ target.set('html',res); });
	}
	
	function perbuatan_save(form){
		FBModal_loading("Save", "Please wait...", true, false);
		$(form).set('send', {
			url:APP.action,
			method:'post',
			onSuccess: function(response) { 
				var js = JSON.decode(response);
				var msg = js.error? js.msg : "Process simpan selesai !!!";
				var title = js.error? 'Error' : 'Saving';
				if (js.error){
					FBModal_show(
						"<h2 class=\"dialog_title\"><span>"+title+"</span></h2>" + 
						"<div class=\"dialog_content\" style=\"padding: 10px 20px\">"+msg+"</div>",
						true, true);
				}else{
					FBModal_show(
						"<h2 class=\"dialog_title\"><span>"+title+"</span></h2>" + 
						"<div class=\"dialog_content\" style=\"padding: 10px 20px\">"+msg+"</div>",
						true, true);
					var xx = function(){document.location='dashboard.php?p=perbuatan'};
					xx.delay(1000);
				}
			}
		}).send();	
	}

var APP = { action: 'proc/client/perbuatan.php' };
window.addEvent('domready', function() {
	$$('.inp-nonKaryawan').setStyle('display', 'none');
	//APP.wkt_lapor = dtpicker_attach0($('wkt_lapor'), {timePicker:true, format: 'd-F-Y H:m:s', 
	//	onClose: function(){ 
	//		APP.wkt_kejadian.options.maxDate = {date:APP.wkt_lapor.attachTo.value, format:'U'};
	//		APP.wkt_kejadian.formatMinMaxDates();
	//	}
	//});
	APP.wkt_kejadian = dtpicker_attach0($('wkt_kejadian'), {maxDate:{ date: <?php echo time()?>, format: 'U' }, timePicker:true, format: 'd-F-Y H:m:s'});
	
	upload_attach(APP.action+'?proc=upload', {
		onFileSuccess: function(file, response) {
			var json = JSON.decode(response);
			//alert(json.src);
			new Element('input', {type: 'checkbox', 'checked': true, name: 'inp[10][]', value:json.src}).inject(file.ui.element, 'top');
			file.ui.element.highlight('#e6efc2');
		}			  
	});
});
</script>
<form id="frmPerbuatan" name="frmPerbuatan" method="post" enctype="multipart/form-data">
<?php 
	//load data karyawan
	$laporData = mysql_fetch_assoc(pelapor_load(false, $_COOKIE_DATA->username));
?>
<input type="hidden" value="perbuatan-add" name="proc" value="<?php echo $laporData['LAPOR_ID'] ?>" />
<input name="inp[0]" type="hidden" readonly="readonly" value="<?php echo $laporData['LAPOR_ID']?>" />
<input name="inp[1][1][1]" type="hidden" value="<?php echo $_COOKIE_DATA->username?>" />
<h2 class="dialog_title" style="border-bottom:1px solid #333; padding-top:20px">Informasi Kejadian</h2>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td align="right">Waktu laporan :</td>
    <td><input name="inp[2-fake]" type="text" value="<?php echo date("d-M-Y H:m:s", time())?>" readonly="readonly" />
    	<input name="inp[2]" id="wkt_lapor" type="hidden" value="<?php echo time()?>" /></td>
  </tr>
  <tr>
    <td align="right">Waktu kejadian : </td>
    <td><input name="inp[3]" id="wkt_kejadian" type="text" /></td>
  </tr>
  <tr>
    <td align="right">Karyawan pelaku : </td>
    <td width="82%"><input name="inp[4]" id="pelaku_karyawan_nik" type="text" readonly="readonly" />
      <input type="button" value="search" onclick="karyawanPelaku_search()" /></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td><input type="text" id="pelaku_karyawan_nama" readonly="readonly" /></td>
  </tr>
  <tr>
    <td align="right">Tempat kejadian : </td>
    <td><input type="text" name="inp[5]" /></td>
  </tr>
  <tr>
    <td align="right">Tipe Pres/Pel </td>
    <td><select name="inp[6]" id="achiev_jenis" onchange="doAdd_bidangCombo(this.value, $('achiev_bidang'))">
      <option value="prestasi">Prestasi</option>
      <option value="pelanggaran">Pelanggaran</option>
      </select></td>
  </tr>
  <tr>
    <td align="right">Bidang Pres/Pel :</td>
    <td><select name="inp[7]" id="achiev_bidang" onchange="doAdd_tingkatCombo($('achiev_jenis').value, this.value, $('detachiev_tingkat'))">
      <?php $res = perpel_select2(false, "ACHIEV_JENIS='prestasi'", "ACHIEV_BIDANG ASC", "ACHIEV_BIDANG"); ?>
      <?php while($row = mysql_fetch_assoc($res)): ?>
      <?php 	$bidang = !$bidang? $row['ACHIEV_BIDANG'] : $bidang ?>
      <option value="<?php echo $row['ACHIEV_BIDANG']?>"><?php echo $row['ACHIEV_BIDANG']?></option>
      <?php endwhile;?>
    </select></td>
  </tr>
  <tr>
    <td align="right">Tingkat Pres/Pel : </td>
    <td><select name="inp[8]" id="detachiev_tingkat" onchange="doAdd_kategoriCombo($('achiev_jenis').value, $('achiev_bidang').value, this.value, $('detachiev_id'))">
      <?php $grp = deprepel_select_corelate(false, "a.ACHIEV_JENIS='prestasi' AND a.ACHIEV_BIDANG='$bidang'", "DETACHIEV_TINGKAT ASC", "DETACHIEV_TINGKAT");?>
      <?php while ($grp_r = mysql_fetch_assoc($grp)): ?>
      <?php $tingkat = !$tingkat? $grp_r['DETACHIEV_TINGKAT'] : $tingkat ?>
      <option value="<?php echo $grp_r['DETACHIEV_TINGKAT']?>"><?php echo $grp_r['DETACHIEV_TINGKAT']?></option>
      <?php endwhile; ?>
    </select></td>
  </tr>
  <tr>
    <td align="right">Kategori Pres/Pel : </td>
    <td><select id="detachiev_id" name="inp[9]">
      <?php $grp = deprepel_select_corelate(false, "a.ACHIEV_JENIS='prestasi' AND a.ACHIEV_BIDANG='$bidang' AND DETACHIEV_TINGKAT='$tingkat'", "DETACHIEV_NAMA ASC", "DETACHIEV_NAMA"); ?>
      <?php while ($grp_r = mysql_fetch_assoc($grp)): ?>
      <option value="<?php echo $grp_r['DETACHIEV_ID']?>"><?php echo $grp_r['DETACHIEV_NAMA']?></option>
      <?php endwhile; ?>
    </select></td>
  </tr>
  <tr>
    <td align="right" valign="top">Dokumen : </td>
    <td>
    	<a href="#" id="demo-attach">Attach a file</a>
        <ul id="demo-list"></ul>
        <a href="#" id="demo-attach-2" style="display: none;">Attach another file</a>
    </td>
  </tr>
  <tr>
    <td align="right" valign="top">Keterangan :</td>
    <td><textarea name="inp[11]" id="" cols="45" rows="5"></textarea></td>
  </tr>
  </table>
<div align="center" class="padT10">
<input type="button" value="Save" name="Save" style="margin-right:5px" onclick="perbuatan_save($(this).getParent('form'))" />
<input type="button" value="Close" name="Cancel" onclick="document.location='dashboard.php?p=perbuatan'" />
</div>
</form>